package com.asurplus.api.controller;

import com.asurplus.business.entity.AppVersion;
import com.asurplus.business.service.AppVersionService;
import com.asurplus.common.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "APP版本控制")
@RestController
@RequestMapping("/api/app")
public class AppVersionApiController {

    @Autowired
    private AppVersionService appLevelLogService;

    @ApiOperation(value = "根据版本号获取APP版本信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "versionCode", value = "版本号", required = true)
    })
    @PostMapping("getAppLevelInfo")
    public R getAppLevelInfo(String versionCode) {
        LambdaQueryWrapper<AppVersion> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.gt(AppVersion::getVersionCode, versionCode);
        queryWrapper.orderByDesc(AppVersion::getCreateTime);
        return R.ok(appLevelLogService.getOne(queryWrapper, false));
    }

    @ApiOperation(value = "获取当前APP最新版本")
    @PostMapping("getNewestAppLevelInfo")
    public R getNewestAppLevelInfo() {
        LambdaQueryWrapper<AppVersion> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(AppVersion::getVersionCode);
        return R.ok(appLevelLogService.getOne(queryWrapper, false));
    }
}
